# Put all necessary libraries here
library(tidyverse)
library(leaflet)
library(tidycensus)
For this problem we will return to the biketown dataset.
StartLatitude,
StartLongitude).biketown_data <- bind_rows(readr::read_csv("https://s3.amazonaws.com/biketown-tripdata-public/2017_01.csv"),
readr::read_csv("https://s3.amazonaws.com/biketown-tripdata-public/2017_07.csv"),
readr::read_csv("https://s3.amazonaws.com/biketown-tripdata-public/2017_11.csv")) %>%
select(StartDate, StartTime, EndDate, EndTime, Distance_Miles,
BikeID, StartLongitude, StartLatitude )
leaflet package. Make sure to include a legend and a title.
What do you notice about the distribution of rides?biketown_data %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(lng = ~StartLongitude, lat = ~StartLatitude)
Here we can see that the bulk of the rides start in the very center of the portland with a slighty denser amount on the west side of the river
lubridate package, create a variable,
month, indicating the month of each variable.Add this variable to your interactive map using color. Make sure to include a legend and be mindful of your color palette choice. Do ride locations vary by months of the year?
biketown_data <- biketown_data %>%
mutate(month = month(ymd_hms(EndDate)))
biketown_data$EndDate <- mdy(biketown_data$EndDate)
biketown_data <- biketown_data %>%
mutate(month = month(EndDate))
month_palette <- colorFactor(palette = "Set3", domain = unique(biketown_data$month))
biketown_data %>%
leaflet() %>%
addTiles() %>%
addCircleMarkers(lng = ~StartLongitude, lat = ~StartLatitude,
fillColor = ~month_palette(month),
color = "black", radius = 5, opacity = 1) %>%
addLegend(position = "bottomright",
colors = month_palette(unique(biketown_data$month)),
labels = month.abb[unique(biketown_data$month)],
title = "Month")
For this problem, I want you to practice creating choropleth maps.
Let’s grab some data using tidycensus. Remember that you
will have to set up an API key.
api_key <- "94a98843fc99d4851ad1aafc71cddde2bfb1385b"
B25064_001)
from the American Community Survey for Multnomah county, Oregon. I want
you to do data pulls at three geography resolutions: county subdivision,
tract, and block group.county_subdivision_data <- get_acs(geography = "county subdivision",
variables = "B25064_001",
state = "OR", county = "Multnomah")
tract_data <- get_acs(geography = "tract",
variables = "B25064_001",
state = "OR", county = "Multnomah")
block_group_data <- get_acs(geography = "block group",
variables = "B25064_001",
state = "OR", county = "Multnomah")